<?php 
	$allTables =($PHPFoxEngine->database->query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '".$PHPFoxEngine->db_base."' GROUP BY TABLE_NAME;"));
	if(mysql_num_rows($allTables) == 0){ echo '<dbresult>2</dbresult>';return;}
	while($table = mysql_fetch_assoc($allTables)){
		$PHPFoxEngine->dbFields[$table['TABLE_NAME']] = array();
		// ATTENTION : NE FONCTIONNE QUE POUR CLEF UNIQUE. TODO : GESTION DES CLEFS PRIMAIRES MULTIPLES
		$resKey = $PHPFoxEngine->database->query("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME = '".$table['TABLE_NAME']."';");
		if(mysql_num_rows($resKey) == 0){ echo '<dbresult>3</dbresult>';return;}
		$key = mysql_fetch_assoc($resKey);
		$PHPFoxEngine->dbFields[$table['TABLE_NAME']]['primary_key'] = $key['COLUMN_NAME'];
		$PHPFoxEngine->dbFields[$table['TABLE_NAME']]['columns'] = array();
		$allColumns = $PHPFoxEngine->database->query("SELECT COLUMN_NAME,DATA_TYPE,IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '".$table['TABLE_NAME']."';");
		if(mysql_num_rows($allColumns) == 0){ echo '<dbresult>4</dbresult>';return;}
		while($column = mysql_fetch_assoc($allColumns)){
			$PHPFoxEngine->dbFields[$table['TABLE_NAME']]['columns'][$column['COLUMN_NAME']]['value'] = "";
			$PHPFoxEngine->dbFields[$table['TABLE_NAME']]['columns'][$column['COLUMN_NAME']]['type'] = $column['DATA_TYPE'];
			$PHPFoxEngine->dbFields[$table['TABLE_NAME']]['columns'][$column['COLUMN_NAME']]['nullable'] = $column['IS_NULLABLE'];
		}
	}
	echo ($PHPFoxEngine->saveDbFields())? '<dbresult>1</dbresult>':'<dbresult>0</dbresult>';
?>